package com.jingdianjichi.auth.common.entity;

import com.jingdianjichi.auth.common.enums.ResultCode;
import lombok.Data;

/**
 * 返回结果类
 *
 * @param <T>
 */
@Data
public class Result<T> {

    private Boolean success;
    private Integer code;
    private String message;
    private T data;

    public static Result ok() {
        Result result = new Result();
        result.setSuccess(true);
        result.setCode(ResultCode.SUCCESS.getCode());
        result.setMessage(ResultCode.SUCCESS.getDesc());
        return result;
    }

    public static <T> Result ok(T data) {
        Result result = new Result();
        result.setSuccess(true);
        result.setCode(ResultCode.SUCCESS.getCode());
        result.setMessage(ResultCode.SUCCESS.getDesc());
        result.setData(data);
        return result;
    }

    public static Result fail() {
        Result result = new Result();
        result.setSuccess(false);
        result.setCode(ResultCode.FAIL.getCode());
        result.setMessage(ResultCode.FAIL.getDesc());
        return result;
    }

    /**
     * 失败返回结果
     *
     * @param data 返回数据
     * @param <T>  T
     * @return Result
     */
    public static <T> Result fail(T data) {
        Result result = new Result();
        result.setSuccess(false);
        result.setCode(ResultCode.FAIL.getCode());
        result.setMessage(ResultCode.FAIL.getDesc());
        result.setData(data);
        return result;
    }

}
